package com.powernode.controller;

import com.powernode.domain.Category;
import com.powernode.domain.IndexImg;
import com.powernode.domain.Product;
import com.powernode.service.CategoryService;
import com.powernode.service.IndexImgService;
import com.powernode.service.ProductService;
import com.powernode.vo.IndexResult;
import com.powernode.vo.ResultVO;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.transform.Result;
import java.util.List;

/**
 * 首页控制器
 * 刘冠志
 * 2023/1/14
 */

@RestController
@RequestMapping("/index")
@Api(tags = "首页管理",value = "提供首页的展示接口")
@CrossOrigin
public class IndexController {


    /**
     * 首页server
     */
    @Autowired
    private IndexImgService indexImgService;

    /**
     * 分类server
     */
    @Autowired
    private CategoryService categoryService;


    /**
     * 商品server
     */
    @Autowired
    private ProductService productService;

    /**
     * 首页轮播图查询
     * @return
     */
    @GetMapping("/indeximg")
    public ResultVO<List<IndexImg>> indeximg(){
        List<IndexImg> list = indexImgService.selectByImg();
        if (list.size()==0){
            return ResultVO.success(IndexResult.INDEXIMG_NO_CODE,"查询为空");
        }
        ResultVO<List<IndexImg>> success = ResultVO.success(list);
        return success;
    }

    /**
     * 首页查询分类列表
     */
    @GetMapping("/category-list")
    public ResultVO<List<Category>> categoryList(){
        List<Category> list = categoryService.selectByList();
        ResultVO<List<Category>> success = ResultVO.success(list);
        return success;
    }

    /**
     * 首页查询新品推荐
     */
    @GetMapping("/list-recommends")
    public ResultVO<List<Product>> listRecommends(){
        List<Product> list = productService.selectRecommGoods();
        ResultVO<List<Product>> success = ResultVO.success(list);
        return success;
    }


    /**
     * 首页查询新品推荐
     */
    @GetMapping("/category-recommends")
    public ResultVO<List<Category>> categoryRecommends(){
        List<Category> list = categoryService.selectByListFirst();
        ResultVO<List<Category>> success = ResultVO.success(list);
        return success;
    }
}
